package com.rosense.server.controller;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

import org.springframework.stereotype.Controller;
import org.springframework.web.bind.ServletRequestDataBinder;
import org.springframework.web.bind.annotation.InitBinder;
import org.springframework.web.bind.annotation.ModelAttribute;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;

/**
 * Author 李岩飞
 * Email eliyanfei@126.com
 * 2017/11/21
 */
@Controller
@RequestMapping(value = "base")
public class BaseController {
	public HttpServletRequest request;
	public HttpServletResponse response;
	public HttpSession session;

	/**
	 * 每次执行请求前都会先执行它再执行请求
	 *
	 * @param request
	 * @param response
	 */
	@ModelAttribute
	public void setServletApi(HttpServletRequest request, HttpServletResponse response) {
		this.request = request;
		this.response = response;
		this.response.setContentType("application/json;charset=UTF-8");//
		this.session = request.getSession();
	}
	
	@InitBinder
	public void initBinder(ServletRequestDataBinder binder) {
	}

	@RequestMapping(value = "error", method = RequestMethod.GET)
	public String norole() throws Exception {
		return "error/error";
	}
}
